package cn.tedu.store.product.webapi.controller;

import cn.tedu.store.commons.pojo.product.vo.HomeBrandListItemVO;
import cn.tedu.store.commons.pojo.product.vo.HomeBrandStandardVO;
import cn.tedu.store.product.service.IHomeBrandService;
import cn.tedu.store.commons.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页推荐品牌控制器
 *
 * @author RelentlessFlow
 * @version 0.0.1
 */
@Slf4j
@Api(tags = "12.首页推荐品牌管理模块")
@RestController
@RequestMapping("/home-brand")
public class HomeBrandController {
    @Autowired
    private IHomeBrandService homeBrandService;

    @ApiOperation("删除推荐品牌")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "推荐品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理[删除推荐品牌]的请求 参数:{}", id);
        homeBrandService.delete(id);
        log.debug("删除推荐品牌成功!");
        return JsonResult.ok();
    }

    @ApiOperation("启用推荐品牌")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "推荐品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/recommend")
    public JsonResult<Void> setRecommend(@PathVariable Long id) {
        log.debug("准备处理[启用推荐品牌]请求 参数:{}", id);
        homeBrandService.setRecommend(id);
        return JsonResult.ok();
    }

    @ApiOperation("禁用推荐品牌")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "推荐品牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/unrecommend")
    public JsonResult<Void> setNotRecommend(@PathVariable Long id) {
        log.debug("准备处理[禁用推荐品牌]请求 参数:{}", id);
        homeBrandService.setNotRecommend(id);
        return JsonResult.ok();
    }

    @ApiOperation("获取推荐品牌详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "推荐品牌id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}/get-by-id")
    public JsonResult<HomeBrandStandardVO> getStandardById(@PathVariable Long id){
        log.debug("开始处理[获取推荐品牌详情]请求 参数:{}",id);
        return JsonResult.ok(homeBrandService.getStandardById(id));
    }

    @ApiOperation("获取推荐品牌列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<HomeBrandListItemVO>> list(){
        log.debug("开始处理[获取推荐品牌列表]请求 参数:无");
        return JsonResult.ok(homeBrandService.list());
    }
}
